<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>注册</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/admin.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/login.css}" media="all">
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
  <div class="layadmin-user-login-main">
    <div class="layadmin-user-login-box layadmin-user-login-header">
      <h2>注册</h2>
      <p>统一后台管理系统</p>
    </div>
    <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
      <div class="layui-form-item">
        <div class="layui-input-wrap">
          <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
          <input type="text" name="mobile" id="LAY-user-login-cellphone" lay-verify="phone" placeholder="手机" class="layui-input" lay-affix="clear">
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-row">
          <div class="layui-col-xs7">
            <div class="layui-input-wrap">
              <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
              <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="验证码" class="layui-input" lay-affix="clear">
            </div>
          </div>
          <div class="layui-col-xs5">
            <div style="margin-left: 10px;">
              <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="LAY-user-getsmscode">获取验证码</button>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-wrap">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
          <input type="text" name="username" id="LAY-user-login-username" lay-verify="username" placeholder="用户名" class="layui-input" lay-affix="clear">
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-wrap">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
          <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass" placeholder="密码" class="layui-input" lay-affix="eye">
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-wrap">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
          <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input" lay-affix="eye">
        </div>
      </div>
      <!--        <div class="layui-form-item">-->
      <!--          <input type="checkbox" name="agreement" lay-skin="primary" title="同意用户协议" checked>-->
      <!--        </div>-->
      <div class="layui-form-item">
        <button class="layui-btn layui-btn-normal layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit">注 册</button>
      </div>
      <div class="layui-trans layui-form-item layadmin-user-login-other">
        <label>社交账号注册</label>
        <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
        <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
        <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>

        <a th:href="@{/auth/login/page}" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
        <!--          <a href="login.html" class="layadmin-user-jump-change layadmin-link layui-hide-sm layui-show-xs-inline-block">登入</a>-->
      </div>
    </div>
  </div>

  <div class="layui-trans layadmin-user-login-footer">

    <p>© 2023 <a href="www.llyong.cn/" target="_blank">www.llyong.cn</a></p>
  </div>

</div>

<script th:src="@{/layui/layui.js}"></script>
<script>
  layui.config({
    base: '/' //静态资源所在路径
  }).use(['index', 'user'], function () {
    let $ = layui.$;
    let setter = layui.setter;
    let admin = layui.admin;
    let form = layui.form;
    let router = layui.router();

    form.render();

    //提交
    form.on('submit(LAY-user-reg-submit)', function (obj) {
      let field = obj.field;

      //确认密码
      if (field.password !== field.repass) {
        return layer.msg('两次密码输入不一致');
      }

      delete field.repass;

      //是否同意用户协议
      // if (!field.agreement) {
      //   return layer.msg('你必须同意用户协议才能注册');
      // }

      //请求接口
      admin.req({
        url: '/auth/register' //实际使用请改成服务端真实接口
        , type: 'post'
        , data: field
        , done: function (res) {
            layer.msg('注册成功', {
              offset: '15px'
              , icon: 1
              , time: 600
            }, function () {
              //跳转到登入页
              window.top.location.href = '/auth/login/page';
            });
        }
      });

      return false;
    });

    //发送短信验证码
    admin.sendAuthCode({
      elem: '#LAY-user-getsmscode'
      ,elemPhone: '#LAY-user-login-cellphone'
      ,elemVercode: '#LAY-user-login-vercode'
      // ,ajax: {
      //   url: layui.setter.paths.base + 'auth/code' //实际使用请改成服务端真实接口
      // }
    });

  });
</script>
</body>
</html>